<style>

</style>
<template>
    <Form ref="list" :model="list" :label-width="100" label-position="right" :rules="rule">
        <FormItem label="问题" prop="question">
            <Input v-model="list.question" placeholder="请输入常见问题"></Input>
        </FormItem>
        <FormItem label="答案" prop="answer">
            <Input type="textarea" v-model="list.answer" placeholder="请输入常见问题答案"></Input>
        </FormItem>
        <FormItem label="排序值" prop="listorder">
            <Input v-model="list.listorder" placeholder="请输入排序值"></Input>
        </FormItem>
        <FormItem>
            <Button type="primary" @click="handleSubmit('list')">确认</Button>
            <Button type="ghost" @click="handleReset('list')" style="margin-left: 10px">重置</Button>
        </FormItem>
    </Form>
</template>
<script>
import http from '../../../libs/http';
export default {
    data() {
        return {
            list: {},
            rule:{
                question: [{required: true, message: '问题不能为空', trigger: 'blur'}],
                answer: [{required: true, message: '答案不能为空', trigger: 'blur'}],
            }
        }
    },
    methods: {
        handleSubmit(name) {
            this.$refs[name].validate((valid) => {
                if (valid) {
                    //提交后台
                    var data = {
                        question: this.list.question,
                        answer: this.list.answer,
                        listorder: this.list.listorder
                    }
                    var url = 'admin/help/save/';
                    this.apiPost(url, data).then((res) => {
                        if (res.code != 200) {
                            this.handleError(res);
                        } else {
                            this.$Message.success('添加成功');
                            this.handleReset(name);
                            this.$emit('closeAdd');
                        }
                    })
                } else {
                    this.$Message.error('表单验证失败!');
                }
            })
        },
        handleReset (name) {
            this.$refs[name].resetFields();
        }
    },
    mixins: [http]
}
</script>
